/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

Ext.ns('AIR2.Import.Resolve');
/***************
 * AIR2 Import Resolution ButtonGroup component
 *
 * A container of buttons to allow the resolution of conflicts on an import.
 *
 * @class AIR2.Import.Resolve.BtnGroup
 * @extends Ext.Container
 * @xtype air2resolvegroup
 * @cfg {String} model
 *
 */
AIR2.Import.Resolve.BtnGroup = function(cfg) {
    cfg.defaults = {
        xtype: 'air2button',
        air2size: 'MEDIUM',
        hideMode: 'display',
        hidden: true,
        enableToggle: true,
        allowDepress: false,
        toggleGroup: cfg.model,
        toggleHandler: this.btnClicked,
        scope: this
    };

    // add buttons
    cfg.items = [
        {air2type: 'NEW', text: 'ADD', opCode: 'A'},
        {air2type: 'BLUE', text: '< UPDATE', opCode: 'R'},
        {air2type: 'PLAIN', text: 'IGNORE', opCode: 'I'}
    ];

    // hidden form field
    this.field = new Ext.form.TextField({
        hidden: true,
        hideMode: 'display',
        name: cfg.model
    });
    cfg.items.push(this.field);

    cfg.layout = {
        type: 'vbox',
        pack: 'start',
        align: 'center'
    };

    AIR2.Import.Resolve.BtnGroup.superclass.constructor.call(this, cfg);
}
Ext.extend(AIR2.Import.Resolve.BtnGroup, Ext.Container, {
    cls: 'column-center',
    height: 100,
    btnClicked: function(btn, state) {
        this.addClass('has-selection');
        if (state) {
            this.field.setValue(btn.opCode);
        }
    },
    setNew: function(allow) {
        this.field.allowBlank = false;
        this.get(0).setVisible(allow);
    },
    setReplace: function(allow) {
        this.field.allowBlank = false;
        this.get(1).setVisible(allow);
    },
    setIgnore: function(allow) {
        this.field.allowBlank = false;
        this.get(2).setVisible(allow);
    }
});
Ext.reg('air2resolvegroup', AIR2.Import.Resolve.BtnGroup);
